<html>
<head>
<title>Code Fragment</title>
</head>

<body text=#000000 bgcolor=#ffffff>
<center>
</center><br><br><dl><dd><pre>

<font color=#ff0080>/**
 * This simple extension of the java.awt.Frame class
 * contains all the elements necessary to act as the
 * main window of an application.
 *
 * @author Robert Cohen (rfc)
 * @version JDSL 2
 */</font>

<font color=#ff8000>import</font> java.awt.*;

<font color=#8000a0>public</font> <font color=#8000a0><font color=#ff8000>class</font> </font>AuctionFrame <font color=#8000a0><font color=#ff8000>extends</font> </font>Frame
{
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#0000ff>AuctionFrame</font>(AuctionSimulator sim)
    {
      <font color=#ff8000>this</font>.sim = sim;
      <font color=#ff0080>// This code is automatically generated by Visual Cafe when you add</font>
      <font color=#ff0080>// components to the visual environment. It instantiates and initializes</font>
      <font color=#ff0080>// the components. To modify the code, only use code syntax that matches</font>
      <font color=#ff0080>// what Visual Cafe can generate, or Visual Cafe may be unable to back</font>
      <font color=#ff0080>// parse your Java file into its visual environment.</font>
      
      <font color=#ff0080>//{{INIT_CONTROLS</font>
      <font color=#0000ff>setLayout</font>(null);
      <font color=#0000ff>setSize</font>(478,301);
      <font color=#0000ff>setVisible</font>(false);
      title.<font color=#0000ff>setText</font>(<font color=#008000>"Auction"</font>);
      <font color=#0000ff>add</font>(title);
      title.<font color=#0000ff>setFont</font>(<font color=#ff8000>new</font> <font color=#0000ff>Font</font>(<font color=#008000>"Dialog"</font>, Font.BOLD, 24));
      title.<font color=#0000ff>setBounds</font>(192,12,100,36);
      item.<font color=#0000ff>setText</font>(<font color=#008000>"Item:"</font>);
      item.<font color=#0000ff>setAlignment</font>(java.awt.Label.RIGHT);
      <font color=#0000ff>add</font>(item);
      item.<font color=#0000ff>setBounds</font>(36,60,43,24);
      highbid.<font color=#0000ff>setText</font>(<font color=#008000>"High Bid:"</font>);
      highbid.<font color=#0000ff>setAlignment</font>(java.awt.Label.RIGHT);
      <font color=#0000ff>add</font>(highbid);
      highbid.<font color=#0000ff>setBounds</font>(17,84,62,24);
      <font color=#0000ff>add</font>(itemDesc);
      itemDesc.<font color=#0000ff>setBounds</font>(96,60,174,24);
      <font color=#0000ff>add</font>(bidDesc);
      bidDesc.<font color=#0000ff>setBounds</font>(96,84,174,24);
      time.<font color=#0000ff>setText</font>(<font color=#008000>"Time"</font>);
      time.<font color=#0000ff>setAlignment</font>(java.awt.Label.RIGHT);
      <font color=#0000ff>add</font>(time);
      time.<font color=#0000ff>setBounds</font>(312,60,43,12);
      remaining.<font color=#0000ff>setText</font>(<font color=#008000>"Remaining"</font>);
      remaining.<font color=#0000ff>setAlignment</font>(java.awt.Label.RIGHT);
      <font color=#0000ff>add</font>(remaining);
      remaining.<font color=#0000ff>setBounds</font>(288,72,67,24);
      <font color=#0000ff>add</font>(clock);
      clock.<font color=#0000ff>setBounds</font>(372,50,50,50);
      yourBid.<font color=#0000ff>setText</font>(<font color=#008000>"Your Bid:"</font>);
      yourBid.<font color=#0000ff>setAlignment</font>(java.awt.Label.RIGHT);
      <font color=#0000ff>add</font>(yourBid);
      yourBid.<font color=#0000ff>setBounds</font>(108,180,62,24);
      startBtn.<font color=#0000ff>setLabel</font>(<font color=#008000>"Start"</font>);
      <font color=#0000ff>add</font>(startBtn);
      startBtn.<font color=#0000ff>setBackground</font>(java.awt.Color.lightGray);
      startBtn.<font color=#0000ff>setBounds</font>(120,216,48,26);
      withdrawBtn.<font color=#0000ff>setLabel</font>(<font color=#008000>"Withdraw"</font>);
      <font color=#0000ff>add</font>(withdrawBtn);
      withdrawBtn.<font color=#0000ff>setBackground</font>(java.awt.Color.lightGray);
      withdrawBtn.<font color=#0000ff>setBounds</font>(180,216,72,26);
      withdrawBtn.<font color=#0000ff>setEnabled</font>(false);
      resetBtn.<font color=#0000ff>setLabel</font>(<font color=#008000>"Reset"</font>);
      <font color=#0000ff>add</font>(resetBtn);
      resetBtn.<font color=#0000ff>setBackground</font>(java.awt.Color.lightGray);
      resetBtn.<font color=#0000ff>setBounds</font>(264,216,48,26);
      quitBtn.<font color=#0000ff>setLabel</font>(<font color=#008000>"Quit"</font>);
      <font color=#0000ff>add</font>(quitBtn);
      quitBtn.<font color=#0000ff>setBackground</font>(java.awt.Color.lightGray);
      quitBtn.<font color=#0000ff>setBounds</font>(324,216,48,26);
      <font color=#0000ff>add</font>(msg);
      msg.<font color=#0000ff>setFont</font>(<font color=#ff8000>new</font> <font color=#0000ff>Font</font>(<font color=#008000>"Dialog"</font>, Font.ITALIC, 12));
      msg.<font color=#0000ff>setBounds</font>(84,264,336,24);
      <font color=#0000ff>add</font>(bidField);
      bidField.<font color=#0000ff>setBounds</font>(180,177,190,30);
      numBidders.<font color=#0000ff>setText</font>(<font color=#008000>"Bidders:"</font>);
      numBidders.<font color=#0000ff>setAlignment</font>(java.awt.Label.RIGHT);
      <font color=#0000ff>add</font>(numBidders);
      numBidders.<font color=#0000ff>setBounds</font>(17,108,62,24);
      <font color=#0000ff>add</font>(biddersDesc);
      biddersDesc.<font color=#0000ff>setBounds</font>(96,108,174,24);
      <font color=#0000ff>setTitle</font>(<font color=#008000>"Auction Simulator"</font>);
      <font color=#ff0080>//}}</font>
      
      <font color=#ff0080>//{{INIT_MENUS</font>
      <font color=#ff0080>//}}</font>
      
      <font color=#ff0080>//{{REGISTER_LISTENERS</font>
      <font color=#8000a0>SymWindow </font>aSymWindow = <font color=#8000a0><font color=#ff8000>new</font> </font><font color=#0000ff>SymWindow</font>();
      <font color=#ff8000>this</font>.<font color=#0000ff>addWindowListener</font>(aSymWindow);
      <font color=#8000a0>SymAction </font>lSymAction = <font color=#8000a0><font color=#ff8000>new</font> </font><font color=#0000ff>SymAction</font>();
      quitBtn.<font color=#0000ff>addActionListener</font>(lSymAction);
      startBtn.<font color=#0000ff>addActionListener</font>(sim);
      withdrawBtn.<font color=#0000ff>addActionListener</font>(sim);
      resetBtn.<font color=#0000ff>addActionListener</font>(sim);
      bidField.<font color=#0000ff>addActionListener</font>(sim);
      clock.<font color=#0000ff>addCountDownTimerListener</font>(sim);
      <font color=#ff0080>//}}</font>
    }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#0000ff>AuctionFrame</font>(AuctionSimulator sim, <font color=#8000a0><font color=#8000a0>String</font> </font>title)
    {
      <font color=#ff8000>this</font><font color=#0000ff></font>(sim);
      <font color=#0000ff>setTitle</font>(title);
    }
  
  <font color=#ff0080>/**
    * Shows or hides the component depending on the boolean flag b.
    * @param b  if true, show the component; otherwise, hide the component.
    * @see java.awt.Component#isVisible
    */</font>
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>setVisible</font>(<font color=#8000a0>boolean</font> b)
    {
      <font color=#ff8000>if</font><font color=#0000ff></font>(b)
	{
	  <font color=#0000ff>setLocation</font>(50, 50);
	}	
      <font color=#ff8000>super</font>.<font color=#0000ff>setVisible</font>(b);
    }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>addNotify</font>()
    {
      <font color=#ff0080>// Record the size of the window prior to calling parents addNotify.</font>
      <font color=#8000a0>Dimension </font>d = <font color=#0000ff>getSize</font>();
      
      <font color=#ff8000>super</font>.<font color=#0000ff>addNotify</font>();
      
      <font color=#ff8000>if</font><font color=#0000ff> </font>(fComponentsAdjusted)
	<font color=#ff8000>return</font>;
      
      <font color=#ff0080>// Adjust components according to the insets</font>
      <font color=#0000ff>setSize</font>(<font color=#0000ff>getInsets</font>().left + <font color=#0000ff>getInsets</font>().right + d.width, <font color=#0000ff>getInsets</font>().top + <font color=#0000ff>getInsets</font>().bottom + d.height);
      <font color=#8000a0>Component </font>components[] = <font color=#0000ff>getComponents</font>();
      <font color=#ff8000>for</font><font color=#0000ff> </font>(<font color=#8000a0>int</font> i = 0; i &lt components.length; i++)
	{
	  <font color=#8000a0>Point </font>p = components[i].<font color=#0000ff>getLocation</font>();
	  p.<font color=#0000ff>translate</font>(<font color=#0000ff>getInsets</font>().left, <font color=#0000ff>getInsets</font>().top);
	  components[i].<font color=#0000ff>setLocation</font>(p);
	}
      fComponentsAdjusted = true;
    }
  
  <font color=#ff0080>// Used for addNotify check.</font>
  <font color=#8000a0><font color=#8000a0>boolean</font> </font>fComponentsAdjusted = false;
  
  <font color=#ff0080>//{{DECLARE_CONTROLS</font>
  java.awt.Label title = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.Label item = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.Label highbid = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.Label itemDesc = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.Label bidDesc = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.Label time = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.Label remaining = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  <font color=#ff0080>//java.awt.Canvas clock = new java.awt.Canvas();</font>
  <font color=#8000a0>CountDownTimer </font>clock = <font color=#8000a0><font color=#ff8000>new</font> </font><font color=#0000ff>CountDownTimer</font>(25);
  java.awt.Label yourBid = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.Button startBtn = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Button</font>();
  java.awt.Button withdrawBtn = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Button</font>();
  java.awt.Button resetBtn = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Button</font>();
  java.awt.Button quitBtn = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Button</font>();
  java.awt.Label msg = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.TextField bidField = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>TextField</font>();
  java.awt.Label numBidders = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  java.awt.Label biddersDesc = <font color=#8000a0><font color=#ff8000>new</font> </font>java.awt.<font color=#0000ff>Label</font>();
  <font color=#ff0080>//}}</font>
  
  <font color=#8000a0>AuctionSimulator </font>sim;
  
  <font color=#ff0080>//{{DECLARE_MENUS</font>
  <font color=#ff0080>//}}</font>
  
  <font color=#8000a0><font color=#ff8000>class</font> </font>SymWindow <font color=#8000a0><font color=#ff8000>extends</font> </font>java.awt.event.WindowAdapter
  {
    <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>windowClosing</font>(java.awt.event.WindowEvent event)
      {
	<font color=#8000a0>Object </font>object = event.<font color=#0000ff>getSource</font>();
	<font color=#ff8000>if</font><font color=#0000ff> </font>(object == AuctionFrame.<font color=#ff8000>this</font>)
	  <font color=#0000ff>AuctionFrame_WindowClosing</font>(event);
      }
  }
  
  <font color=#8000a0><font color=#8000a0>void</font> </font><font color=#0000ff>AuctionFrame_WindowClosing</font>(java.awt.event.WindowEvent event)
    {
      <font color=#0000ff>quit</font>();
    }
  
  <font color=#8000a0><font color=#8000a0>private</font> </font><font color=#8000a0>void</font> <font color=#0000ff>quit</font>() {
    System.<font color=#0000ff>exit</font>(0);
  }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>setItem</font>(<font color=#8000a0>String</font> s) {
    itemDesc.<font color=#0000ff>setText</font>(s);
  }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>setHighBid</font>(<font color=#8000a0>double</font> d) {
    bidDesc.<font color=#0000ff>setText</font>(<font color=#8000a0>String</font>.<font color=#0000ff>valueOf</font>(d));
  }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>setNumBidders</font>(<font color=#8000a0>int</font> n) {
    biddersDesc.<font color=#0000ff>setText</font>(<font color=#8000a0>String</font>.<font color=#0000ff>valueOf</font>(n));
  }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>setMsg</font>(<font color=#8000a0>String</font> message) {
    msg.<font color=#0000ff>setText</font>(message);
  }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>setBid</font>(<font color=#8000a0>String</font> str) {
    bidField.<font color=#0000ff>setText</font>(str);
  }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>String</font> <font color=#0000ff>getName</font>() {
    <font color=#ff8000>return</font> <font color=#008000>"Your Name"</font>;
  }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>double</font> <font color=#0000ff>getBid</font>() {
    <font color=#8000a0><font color=#8000a0>String</font> </font>str = bidField.<font color=#0000ff>getText</font>();
    <font color=#0000ff>setBid</font>(<font color=#008000>""</font>);
    <font color=#ff8000>try</font> {
      <font color=#8000a0><font color=#ff8000>return</font> </font>Double.<font color=#0000ff>parseDouble</font>(str);
    } <font color=#ff8000>catch</font><font color=#0000ff> </font>(NumberFormatException e) {
      <font color=#ff8000>return</font> 0; 
    }
  }
  
  <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>clear</font>() {
    <font color=#0000ff>setItem</font>(<font color=#008000>""</font>);
    <font color=#0000ff>setHighBid</font>(0);
    <font color=#0000ff>setNumBidders</font>(0);
    <font color=#0000ff>setMsg</font>(<font color=#008000>""</font>);
  }
  
  
  <font color=#8000a0><font color=#ff8000>class</font> </font>SymAction <font color=#8000a0><font color=#ff8000>implements</font> </font>java.awt.event.ActionListener
  {
    <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>void</font> <font color=#0000ff>actionPerformed</font>(java.awt.event.ActionEvent event)
      {
	<font color=#8000a0>Object </font>object = event.<font color=#0000ff>getSource</font>();
	<font color=#ff8000>if</font><font color=#0000ff> </font>(object == quitBtn)
	  <font color=#0000ff>quitBtn_ActionPerformed</font>(event);
      }
  }
  
  
  <font color=#8000a0><font color=#8000a0>void</font> </font><font color=#0000ff>quitBtn_ActionPerformed</font>(java.awt.event.ActionEvent event)
    {
      <font color=#ff0080>// to do: code goes here.</font>
      
      <font color=#0000ff>quitBtn_ActionPerformed_Interaction1</font>(event);
    }
  
  <font color=#8000a0><font color=#8000a0>void</font> </font><font color=#0000ff>quitBtn_ActionPerformed_Interaction1</font>(java.awt.event.ActionEvent event)
    {
      <font color=#ff8000>try</font> {
	<font color=#ff8000>this</font>.<font color=#0000ff>quit</font>();
      } <font color=#ff8000>catch</font><font color=#0000ff> </font>(Exception e) {
      }
    }
}

</dl>
</body>
</html>
